angular.module('mamApp').controller('twoLevelModelController', ['$scope', '$state', '$uibModal','ImsDialog','ChannelManager','$filter','$uibModalInstance','data',
    function ($scope, $state, $uibModal, ImsDialog, ChannelManager, $filter, $uibModalInstance, data) {

    $scope.formData = data;
    $scope.table = JSON.parse(localStorage.getItem("codeTable"));

    $scope.initData = {
        "status": ["4", "2"]
    };

        $scope.message="";
    ChannelManager.categoriesList([1,1000]).then(function (result) {
        $scope.categoriesList = result.data.pageList;
    });


    //新建确定(频道名称是否存在后台判断)
    $scope.okCreate = function () {
        ChannelManager.channelsAdd($scope.formData).then(function (result) {
            if(result.data.c=="s"){
                $uibModalInstance.close("ok");
            } else {
                $scope.nameCheck = true;
                $scope.message=result.data.i;
            }
        });
    };

    //编辑确定(频道名称是否存在后台判断)
    $scope.okEdit = function () {
        ChannelManager.channelsEdit($scope.formData.channelId,$scope.formData).then(function (result) {
            if(result.data.c=="s"){
                $uibModalInstance.close("ok");
            } else {
                $scope.nameCheck = true;
                $scope.message=result.data.i;
                //$uibModalInstance.close("error");
            }
        });
    };

    $scope.cancel = function () {
        $uibModalInstance.close("cancel");
    };



}]);

